package com.spring.demo5.eg2;

import org.springframework.aop.ThrowsAdvice;

import java.lang.reflect.Method;
import java.util.Arrays;
import java.util.stream.Collectors;

/**
 * 通过异常通知来捕获所有方法的运行，发现异常之后，通知开发修复bug
 *
 * @author vhans
 */
public class SendMsgThrowsAdvice implements ThrowsAdvice {
    public void afterThrowing(Method method, Object[] args, Object target, RuntimeException e) {
        // 监控到异常后发送信息通知开发者
        System.out.println("异常警报: ");
        System.out.printf("method:[%s],args:[%s]%n", method.toGenericString(), Arrays.stream(args).collect(Collectors.toList()));
        System.out.println(e.getMessage());
        System.out.println("请尽快修复bug!");
    }
}
